//
//  HelpViewController.m
//  ChartsDemo
//
//  Created by wusiping on 2021/4/1.
//

#import "HelpViewController.h"
#import "HelpTableViewCell.h"

@interface HelpViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) NSArray *dataArray;
@property (nonatomic,strong) UITableView *tableView;


@end

@implementation HelpViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self dataConfig];
    [self UIConfig];
}

#pragma mark - dataConfig
- (void)dataConfig
{
    
    self.dataArray = @[@{@"text":FYLocalizedString(@"oxygen_text_no_device_title", @""),@"textAlignment":@(NSTextAlignmentCenter),@"font":[UIFont systemFontOfSize:18]},
                       @{@"text":FYLocalizedString(@"oxygen_text_no_device_title1", @""),@"textAlignment":@(NSTextAlignmentCenter),@"font":[UIFont systemFontOfSize:16]},
                       @{@"text":FYLocalizedString(@"oxygen_text_no_device_content", @""),@"textAlignment":@(NSTextAlignmentCenter),@"font":[UIFont systemFontOfSize:14]},
                       @{@"text":FYLocalizedString(@"oxygen_text_no_device_title2", @""),@"textAlignment":@(NSTextAlignmentCenter),@"font":[UIFont systemFontOfSize:16]},
                       
                       @{@"text":FYLocalizedString(@"oxygen_text_no_device_content1", @""),@"textAlignment":@(NSTextAlignmentCenter),@"font":[UIFont systemFontOfSize:14]},
                       
                       @{@"text":FYLocalizedString(@"oxygen_text_no_device_phone_number", @""),@"textAlignment":@(NSTextAlignmentCenter),@"font":[UIFont systemFontOfSize:14]},
                       ];
}

#pragma mark - UIConfig
- (void)UIConfig
{
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(-10, 0, 47, 27);
    [backBtn setImage:[UIImage imageNamed:@"i_return_black"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
     self.navigationItem.leftBarButtonItem = backItem;
    
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self setTitle:FYLocalizedString(@"app__help", @"")];
    self.tableView = [[UITableView alloc] init];
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.top.equalTo(self.view.mas_top).offset(30);
    }];
    [self.tableView registerClass:[HelpTableViewCell class] forCellReuseIdentifier:@"HelpTableViewCell"];
    [self.tableView reloadData];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

- (void)backClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - refresh
- (void)refresh
{
    [self dataConfig];
    [self.tableView reloadData];
}

#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    NSInteger count = 1;
    return count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSInteger count = self.dataArray.count;
    return count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewAutomaticDimension;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HelpTableViewCell *cell = (HelpTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:@"HelpTableViewCell"];
    if (!cell) {
        cell = [[HelpTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                          reuseIdentifier:@"HelpTableViewCell"];
    }
    NSDictionary *dict = self.dataArray[indexPath.row];
    [cell configCellWithText:dict[@"text"] textAlignment:NSTextAlignmentLeft font:dict[@"font"]];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [super touchesBegan:touches withEvent:event];
}

@end
